package org.dromara.assets.biz;

import com.binance.connector.client.common.configuration.SignatureConfiguration;
import com.binance.connector.client.common.websocket.configuration.WebSocketClientConfiguration;
import com.binance.connector.client.common.websocket.dtos.StreamResponse;
import com.binance.connector.client.common.websocket.service.StreamBlockingQueueWrapper;
import com.binance.connector.client.spot.websocket.api.api.SpotWebSocketApi;
import com.binance.connector.client.spot.websocket.api.model.UserDataStreamEventsResponse;
import com.binance.connector.client.spot.websocket.api.model.UserDataStreamSubscribeResponse;
import com.binance.connector.client.spot.websocket.stream.SpotWebSocketStreamsUtil;
import com.binance.connector.client.spot.websocket.stream.api.SpotWebSocketStreams;
import org.eclipse.jetty.client.HttpProxy;

public class Test {
    public static void main(String[] args) throws Exception {
        // Basic client config
        WebSocketClientConfiguration clientConfiguration = SpotWebSocketStreamsUtil.getClientConfiguration();
        // Create the HTTP proxy
        HttpProxy proxy = new HttpProxy("127.0.0.1", 1081);
        // Add the proxy to the configuration
        clientConfiguration.setWebSocketProxy(proxy);

        SignatureConfiguration signatureConfiguration = new SignatureConfiguration();
        signatureConfiguration.setApiKey("bPGcOcIyZZhQdDFyIC0NoO0zComO7AZ1wMDtgYgN8ttUfHnFfgTfqhCNlT1sOvsK");
        signatureConfiguration.setSecretKey("NlUDq9nF1TSYM9ZPANwL0kHuKo4bYFls5U2A3HzQRpjKpZUacxTs4tmTM8QNnupX");

        clientConfiguration.setSignatureConfiguration(signatureConfiguration);
        // Use with API
        SpotWebSocketApi api = new SpotWebSocketApi(clientConfiguration);

        StreamResponse<UserDataStreamSubscribeResponse, UserDataStreamEventsResponse> resp =
            api.userDataStreamSubscribe();
        resp.getResponse()
            .thenAccept(
                responseResult -> {
                    System.out.println(responseResult);
                });
        StreamBlockingQueueWrapper<UserDataStreamEventsResponse> stream = resp.getStream();
        while (true) {
            System.out.println(stream.take().getActualInstance());
        }


    }
}
